|
|
|
|
|
|
|
Creating an Embedded Object at Designtime |
|
|
|
|
|
|
|
|
As an example, create an embedded Windows Paintbrush object now. First, start a new Standard EXE project and draw the OLE Container control on the form. As soon as you draw the OLE Container control, the Insert Object dialog box, shown in Figure 22.4, appears. |
|
|
|
|
|
|
|
|
Figure 22.4
The Insert Object dialog box lets you
specify an embedded object at designtime. |
|
|
|
|
|
|
|
|
The Insert Object dialog box lists all the available objects that can be used with the OLE control. If you do not select an object, the OLE control becomes a placeholder for an object, which can be created at runtime. For the example, choose Paintbrush Picture and click OK. |
|
|
|
|
|
|
|
|
After choosing an object type and clicking OK, you may have noticed that Visual Basic's toolbars and menus changed. This change happened because the OLE object in the control was activated. When an object is active, you can interact with it. In the sample project, because you created a Paintbrush picture object, you can now draw in the control with the mouse and perform all the drawing operations you normally could in Paintbrush. |
|
|
|
|
|
|
|
|
Draw some lines in the box, and deactivate the object by clicking outside the control on the form. Notice that you can still see your drawing in the inactive object, but the Visual Basic environment has returned to ''normal." When an object is inactive, you cannot interact with it. The DisplayType property of the OLE control determines whether inactive objects are displayed as icons or as the actual contents (that is, the drawing). |
|
|
|
|
|
|
|
|
Run your program by pressing F5, and notice that the object's behavior remains the same. Double-clicking the object activates Paintbrush so that you can edit the object, as shown in Figure 22.5. |
|
|
|
|
|
|
|
|
Saving an Embedded Object to a File |
|
|
|
|
|
|
|
|
Now you can add saving and loading capability to the sample application. Add two command buttons, cmdSave and cmdLoad, to the form and enter the following code: |
|
|
|
|
|
|
|
|
Private Sub cmdSave_Click()
Open "C:\OBJECT.DAT" For Binary As #1
OLE1.SaveToFile 1
Close #1
End Sub
Private Sub cmdLoad_Click()
Open "C:\OBJECT.DAT" For Binary As #1
OLE1.ReadFromFile 1
Close #1
End Sub |
|
|
|
|
|